home *** CD-ROM | disk | FTP | other *** search
/ SCI Games E3 2005 Press Kit (USA) / SCI Games E3 2005 Press Kit (USA).bin / runme_mac.swf / scripts / __Packages / mx / controls / streamingmedia / FLVPlayer.as < prev    next >
Text File  |  2005-05-05  |  5KB  |  214 lines

  1. class mx.controls.streamingmedia.FLVPlayer extends mx.controls.streamingmedia.AbstractPlayer
  2. {
  3.    function FLVPlayer(aMediaUrl, aVideoHolder, aTotalTime)
  4.    {
  5.       super();
  6.       if(aMediaUrl == null || aVideoHolder == null || aTotalTime == null)
  7.       {
  8.       }
  9.       this._mediaUrl = aMediaUrl;
  10.       this._videoHolder = aVideoHolder;
  11.       this._video = this._videoHolder._video;
  12.       this._totalTime = aTotalTime;
  13.       this.init();
  14.    }
  15.    function init()
  16.    {
  17.       this._listeners = new Array();
  18.       this.setPlaying(false);
  19.       this._isLoaded = false;
  20.       this._sound = new Sound(this._videoHolder);
  21.       this.setVolume(mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME);
  22.    }
  23.    function addListener(aListener)
  24.    {
  25.       this._listeners.push(aListener);
  26.    }
  27.    function removeAllListeners()
  28.    {
  29.       this._listeners.length = 0;
  30.    }
  31.    function broadcastEvent(status)
  32.    {
  33.       var _loc2_ = 0;
  34.       while(_loc2_ < this._listeners.length)
  35.       {
  36.          this._listeners[_loc2_].handlePlayer(this,status);
  37.          _loc2_ = _loc2_ + 1;
  38.       }
  39.    }
  40.    function bufferIsFull()
  41.    {
  42.       this.broadcastEvent("start");
  43.       if(!this.isPlaying())
  44.       {
  45.          this.pause();
  46.       }
  47.    }
  48.    function resizeVideo()
  49.    {
  50.       this.broadcastEvent("resizeVideo");
  51.       if(!this.isPlaying())
  52.       {
  53.          this.pause();
  54.       }
  55.    }
  56.    function toString()
  57.    {
  58.       return "FLVPlayer: Playing " + this.getMediaUrl();
  59.    }
  60.    function close()
  61.    {
  62.       this._ns.close();
  63.       this._nc.close();
  64.       this._video.clear();
  65.    }
  66.    function load()
  67.    {
  68.       this._nc = new NetConnection();
  69.       this._nc.connect(null);
  70.       this._ns = new mx.controls.streamingmedia.PlayerNetStream(this._nc,this);
  71.       this.assignBufferTime();
  72.       this._video.attachVideo(this._ns);
  73.       this._videoHeight = this._video.height;
  74.       this._videoWidth = this._video.width;
  75.       this._videoHolder.attachAudio(this._ns);
  76.       this._ns.play(this._mediaUrl);
  77.       this._isLoaded = true;
  78.       this._videoHolder._visible = false;
  79.       this.setPlaying(false);
  80.    }
  81.    function assignBufferTime()
  82.    {
  83.       var _loc2_ = this._totalTime / 4;
  84.       if(_loc2_ < 0.1)
  85.       {
  86.          _loc2_ = 0.1;
  87.       }
  88.       else if(_loc2_ > 5)
  89.       {
  90.          _loc2_ = 5;
  91.       }
  92.       this._ns.setBufferTime(_loc2_);
  93.    }
  94.    function play(startingPoint)
  95.    {
  96.       if(!this._isLoaded)
  97.       {
  98.          this.load();
  99.       }
  100.       if(startingPoint != null)
  101.       {
  102.          this._ns.seek(startingPoint);
  103.       }
  104.       this._ns.pause(false);
  105.       this.setPlaying(true);
  106.    }
  107.    function pause()
  108.    {
  109.       this._ns.pause(true);
  110.       this.setPlaying(false);
  111.    }
  112.    function stop()
  113.    {
  114.       this.pause();
  115.       this.setPlayheadTime(0);
  116.    }
  117.    function getPlayheadTime()
  118.    {
  119.       return this._ns.time;
  120.    }
  121.    function setPlayheadTime(position)
  122.    {
  123.       this._ns.seek(position);
  124.       if(!mx.controls.streamingmedia.StreamingMediaConstants.SCRUBBING)
  125.       {
  126.          if(!this.isPlaying())
  127.          {
  128.             this._ns.pause(false);
  129.             this._momentaryPlayId = setInterval(this,"doneUpdateFrame",50);
  130.          }
  131.       }
  132.    }
  133.    function doneUpdateFrame()
  134.    {
  135.       clearInterval(this._momentaryPlayId);
  136.       this._momentaryPlayId = null;
  137.       this._ns.pause(true);
  138.    }
  139.    function playStopped()
  140.    {
  141.       this.pause();
  142.       this.broadcastEvent("complete");
  143.    }
  144.    function getMediaUrl()
  145.    {
  146.       return this._mediaUrl;
  147.    }
  148.    function setMediaUrl(aUrl)
  149.    {
  150.       this._mediaUrl = aUrl;
  151.       this._isLoaded = false;
  152.       if(this.isPlaying())
  153.       {
  154.          this.play(0);
  155.       }
  156.       else
  157.       {
  158.          this.load();
  159.       }
  160.    }
  161.    function getVolume()
  162.    {
  163.       return this._sound.getVolume();
  164.    }
  165.    function setVolume(aVol)
  166.    {
  167.       this._sound.setVolume(aVol);
  168.    }
  169.    function getMediaBytesLoaded()
  170.    {
  171.       return this._ns.bytesLoaded;
  172.    }
  173.    function getMediaBytesTotal()
  174.    {
  175.       return this._ns.bytesTotal;
  176.    }
  177.    function getTotalTime()
  178.    {
  179.       return this._totalTime;
  180.    }
  181.    function setTotalTime(aTime)
  182.    {
  183.       this._totalTime = aTime;
  184.       this.assignBufferTime();
  185.    }
  186.    function mediaLoaded()
  187.    {
  188.    }
  189.    function logError(error)
  190.    {
  191.    }
  192.    function isSizeSet()
  193.    {
  194.       if(this._video.width > 0 && this._video.height > 0)
  195.       {
  196.          return true;
  197.       }
  198.       return false;
  199.    }
  200.    function isSizeChange()
  201.    {
  202.       if(this._video.width != this._videoWidth || this._video.height != this._videoHeight)
  203.       {
  204.          this._videoWidth = this._video.width;
  205.          this._videoHeight = this._video.height;
  206.          return true;
  207.       }
  208.       return false;
  209.    }
  210.    function setSeeking(isSeeking)
  211.    {
  212.    }
  213. }
  214.